package com.mcptt.db.loader.msg;

import java.util.List;
import java.util.Vector;

import android.annotation.TargetApi;
import android.app.LoaderManager;
import android.content.Context;
import android.content.CursorLoader;
import android.content.Loader;
import android.database.Cursor;
import android.os.Build;
import android.os.Bundle;

import com.cloudptt.api.product.log.Log;
import com.mcptt.db.Callback;
import com.mcptt.db.DBAdapter;
import com.mcptt.db.DbConst;
import com.mcptt.db.model.HistoryInfo;
import com.mcptt.db.model.SessionInfo;

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public class HirstoryListLoader implements Callback
{
	private final static String THIS_FILE = "MsgListLoader";
	private Context ctx = null;
	private HirstoryListLoaderCb callback = null;
	public HirstoryListLoader(Context ctx, DBAdapter dbOperater, HirstoryListLoaderCb callback)
	{
		this.ctx = ctx;
		this.callback = callback;
		dbOperater.queryLargeHistoryList(this);
	}
	@Override
	public void onDataFetched(Cursor data) {
		if (data == null
				|| data.getCount() < 0)
		{
			return;
		}
		Log.debug(this.getClass(),"onLoadFinished Cursor.getCount() = " + data.getCount());
		List<HistoryInfo> list = new Vector<HistoryInfo>();
		Cursor cursor = data;
		while (cursor.moveToNext())
		{
			HistoryInfo info = new HistoryInfo(cursor);
			list.add(info);
		}
		cursor.close();
		cursor = null;

		this.callback.onLoadFinished(list);
	}
}
